package bytecode.proxy.dynamic;

import bytecode.proxy.statics.BJHello;
import bytecode.proxy.statics.Hello;
import net.bytebuddy.pool.TypePool;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy implements InvocationHandler {
    private Object target = null;

    DynamicProxy(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理前");
        method.invoke(target, args);
        System.out.println("代理后");

        return null;

    }

    public static void main(String[] args) {
        Hello hello = new BJHello() ;
        DynamicProxy dyProxy = new DynamicProxy(hello);
        Hello helloProxy = (Hello) Proxy.newProxyInstance(Hello.class.getClassLoader(), new Class[]{Hello.class}, dyProxy);
        helloProxy.welcome();


    }


}
